package com.monscape.tag_c.supportclasses;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;

import com.monscape.tag_c.RootActivity;

public class AppManager {
	public static enum ACTIVITY_INDEX {
		ROOT, TRACKING, SERVICE, LIST, SETTING
	}
	
	private static final String ME = "AppManager";
	private static AppManager _instance = null;
	private Activity _currentActivity = null;
	private Activity _previousActivity = null;

	public SharedPreferences getPreferences() {
		return _currentActivity.getSharedPreferences("setting", Activity.MODE_PRIVATE);
	}

	public Context get_currentContext() {
		return _currentActivity.getApplicationContext();
	}

	public Activity get_currentActivity() {
		return _currentActivity;
	}

	public void set_currentActivity(Activity _currentActivity) {
		_previousActivity = this._currentActivity;
		this._currentActivity = _currentActivity;
	}

	public Activity get_previousActivity() {
		return _previousActivity;
	}
	
	public void showAlertDialog(String title, String message) {
		new AlertDialog.Builder(AppManager.getInstance().get_currentActivity())
		.setTitle(title).setMessage(message)
		.setPositiveButton("확인", new OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				dialog.dismiss();
			}
		}).show();
	}
	
	public void ChangeActivity(ACTIVITY_INDEX index) {
		Intent newIntent = new Intent();

		switch (index) {
		case ROOT:
			newIntent.setClass(_currentActivity, RootActivity.class);
			newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			newIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
			break;
		case TRACKING:
//			newIntent.setClass(_currentActivity, MenuGameActivity.class);
			break;
		case SERVICE:
//			newIntent.setClass(_currentActivity, GambleActivity.class);
			break;
		case LIST:
//			newIntent.setClass(_currentActivity, ControlActivity.class);
			break;
		case SETTING:
//			newIntent.setClass(_currentActivity, ControlActivity.class);
			break;
		default:
			break;
		}

		_currentActivity.startActivity(newIntent);
	}

	public static AppManager getInstance() {
		if (_instance == null) {
			synchronized (AppManager.class) {
				if (_instance == null) {
					_instance = new AppManager();
				}
			}
		}
		return _instance;
	}

	private AppManager() {

	}

}
